import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

import vuexpersist from "vuex-persist"

export default new Vuex.Store({
  state: {
    shopcar:[]
  },
  mutations: {
    add(state, item) {
      var flag = true
      state.shopcar.forEach(res => {
        if (res.title == item.title) {
          console.log(123);
          flag = false
          res.num++
        }
      })
      if (flag == true) {
          item.num=1
          state.shopcar.push(item)
        }
    },
    change() { },
    remove(state, index) {
      state.shopcar.splice(index,1)
    }
  },
  actions: {
  },
  modules: {
  },
 plugins:[
    new vuexpersist({
    storage:window.localStorage,
  }).plugin,
],
})
